<template>
	<view class="">
		<!--  -->
		<ben></ben>
		<!--  -->
		<view class="head_back">

		</view>
		<view class="cartShop column pad20 min30 rad1">
			<!-- 商家列表 -->
			<view class="cartName-box minbottom20">
				<image :src="list[0].shop_logo" class="cartName-img rad1 minright10"></image>
				<view class="omit1 size26 col3 font600" style="max-width:400rpx;">
					{{ list[0].shop_name }}
				</view>
				<view class="minau minright0 size24 font600" style="color: #FE3C3C;">
					待核销
				</view>
			</view>
			<!-- 商品列表 -->
			<u-checkbox-group placement="column" @change="checkboxChange" shape="circle">
				<view class="row" style="margin-bottom: 20rpx;" v-for="(info, k) in list" :key="k">
					<u-checkbox :checked="info.goodsSelected" :name="info.goods_name">

					</u-checkbox>
					<view class="rad1">
						<image :src="info.goods_cover" class="cartDetail-imgs rad1"></image>
					</view>
					<view class="column minleft10 flex1">
						<view class="size28 col3 font600 omit1">{{ info.goods_name }}</view>
						<view class="cartNum minto minbottom10">
							<view class="size24 col9 font500 mintop10">
								规格：{{ info.specs_name }}
							</view>
							<view class="size26 col6 font500">
								数量：{{ info.specs_num }}
							</view>
						</view>
					</view>
				</view>

			</u-checkbox-group>
			<view class="column padtop20" style="border-top: 2rpx solid #f6f6f6;">
				<view class="col3 size26 font500">
					订单编号：{{ order_no }}
				</view>
				<view class="col3 size26 font500 mintop10">
					下单时间：{{ create_time }}
				</view>
				<view class="col3 size26 font500 mintop10">
					实付:￥{{ total_price }}
				</view>
			</view>
		</view>
		<view class="background_f rad1 pad20 min30_rl column">
			<view class="font600 col3 size30">
				退货原因
				<view class="mintop20 row font500">
					<u-radio-group shape="circle" iconPlacement="right" v-model="radiovalue1" placement="cloumn">
						<u-radio v-for="(item, index) in radiolist1" :key="index" activeColor="#FE9110"
							:label="item.name" :name="item.name" labelSize="13" :customStyle="{marginBottom: '10px'}"
							labelColor="#333333"></u-radio>
					</u-radio-group>
				</view>
			</view>
			<view class="font600 col3 size30 mintop10">
				上传照片
				<view class="mintop20 row">
					<u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple
						:maxCount="10"></u-upload>
				</view>
			</view>
			<!-- <view class="font600 col3 size30 mintop10">
				退款金额
				<view class="mintop30 size24 font500">
					<u--input placeholder="请输入退款金额，最高不超过订单实际支付金额" placeholderStyle="color: #999;"
						customStyle="background-color: #f6f6f6;border:#f6f6f6;" border="surround"
						v-model="value"></u--input>
				</view>
			</view> -->
		</view>
		<view class="pad30" style="margin-top: 60rpx;">
			<u-button text="提交退款申请" color="#FFAD4D" @click="">
			</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				order_no: '',
				total_price: '',
				create_time: '',
				list: [],
				fileList1: [],
				radiolist1: [{
						name: '物品损坏',
					},
					{
						name: '未收到商品',
					},
					{
						name: '商品数量不足',
					}
				],
				radiovalue1: '苹果',
			}
		},
		onLoad(op) {
			this.id = op.id
			this.order_no = op.order_no
			this.create_time = op.create_time
			this.total_price = op.total_price
		},
		onShow() {
			//当前页面展示的时候他就执行该生命周期
			const token = uni.getStorageSync('token');
			// this.user_id = uni.getStorageSync('user_id');
			if (token) {
				//如果存在token
				this.getOrderinfo()
				//按正常逻辑来讲 登录成功 我们是不是需要向服务器获取用户的信息？
				//那么我们一起来获取用户信息
			} else {

				uni.showToast({
					title: '您还未登录，正在前往登录',
					icon: 'none'
				})
				setTimeout(function() {
					uni.navigateTo({
						url: "/mypackage/user/login"
					})
				}, 1000)
			}
		},
		methods: {
			async getOrderinfo() {
				let {
					code,
					message,
					data
				} = await this.$com.fetchGet("member/order_info/" + this.id)
				if (code == 200) {
					this.list = data
				} else {
					console.log(message);
				}
			},
			checkboxChange(e) {
				console.log(e);
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: 'http://192.168.2.21:7001/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							setTimeout(() => {
								resolve(res.data.data)
							}, 1000)
						}
					});
				})
			}

		}
	}
</script>

<style scoped lang="less">
	.cartShop {
		box-shadow: 0 0 9rpx 3rpx #ccc;
		background-color: white;
	}

	.cartName {
		font-size: 29rpx;
		color: #333333;
		display: flex;
		align-items: center;
	}

	.cartName-box {
		height: 30rpx;
		display: flex;
		align-items: center;
	}

	.cartName-img {
		width: 50rpx;
		height: 50rpx;
	}

	.cartDetail-imgs {
		width: 200rpx;
		height: 160rpx;
	}

	.cartNum {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
</style>